package cloud.xiguapi.ubas.controller;

import cloud.xiguapi.ubas.analysis.advertising.BlacklistProvinceAdvertisingAnalysis;
import cloud.xiguapi.ubas.analysis.hotitems.FileHotItemsAnalysis;
import cloud.xiguapi.ubas.analysis.hotitems.KafkaHotItemsAnalysis;
import cloud.xiguapi.ubas.analysis.hotitems.SqlHotItemsAnalysis;
import cloud.xiguapi.ubas.analysis.hotpages.FileHotPagesAnalysis;
import cloud.xiguapi.ubas.analysis.hotpages.SocketHotPagesAnalysis;
import cloud.xiguapi.ubas.analysis.login.TimelinessLoginFailAnalysis;
import cloud.xiguapi.ubas.analysis.market.ChannelMarketingAnalysis;
import cloud.xiguapi.ubas.analysis.market.SummaryMarketingAnalysis;
import cloud.xiguapi.ubas.analysis.pv.FilePVAnalysis;
import cloud.xiguapi.ubas.analysis.uv.BloomUVAnalysis;
import cloud.xiguapi.ubas.analysis.uv.SetUVAnalysis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cloud.xiguapi.ubas.constant.FilenameConstant.*;
import static cloud.xiguapi.ubas.constant.GlobalConstant.DEV;
import static cloud.xiguapi.ubas.constant.JobNameConstant.*;

/**
 * @author 大大大西西瓜皮🍉
 * date: 2021-5-17 上午 12:12
 * desc:
 */
@RestController
@RequestMapping("/test")
public class TestController {

    private final FileHotItemsAnalysis fileHotItemsAnalysis;

    private final KafkaHotItemsAnalysis kafkaHotItemsAnalysis;

    private final SqlHotItemsAnalysis sqlHotItemsAnalysis;

    private final FileHotPagesAnalysis fileHotPagesAnalysis;

    private final SocketHotPagesAnalysis socketHotPagesAnalysis;

    private final FilePVAnalysis filePVAnalysis;

    private final SetUVAnalysis setUVAnalysis;

    private final BloomUVAnalysis bloomUVAnalysis;

    private final ChannelMarketingAnalysis channelMarketingAnalysis;

    private final SummaryMarketingAnalysis summaryMarketingAnalysis;

    private final BlacklistProvinceAdvertisingAnalysis blacklistProvinceAdvertisingAnalysis;

    private final TimelinessLoginFailAnalysis timelinessLoginFailAnalysis;

    @Autowired
    public TestController(FileHotItemsAnalysis analysis, KafkaHotItemsAnalysis kafkaHotItemsAnalysis, SqlHotItemsAnalysis sqlHotItemsAnalysis, FileHotPagesAnalysis fileHotPagesAnalysis, SocketHotPagesAnalysis socketHotPagesAnalysis, FilePVAnalysis filePVAnalysis, SetUVAnalysis setUVAnalysis, BloomUVAnalysis bloomUVAnalysis, ChannelMarketingAnalysis channelMarketingAnalysis, SummaryMarketingAnalysis summaryMarketingAnalysis, BlacklistProvinceAdvertisingAnalysis blacklistProvinceAdvertisingAnalysis, TimelinessLoginFailAnalysis timelinessLoginFailAnalysis) {
        this.fileHotItemsAnalysis = analysis;
        this.kafkaHotItemsAnalysis = kafkaHotItemsAnalysis;
        this.sqlHotItemsAnalysis = sqlHotItemsAnalysis;
        this.fileHotPagesAnalysis = fileHotPagesAnalysis;
        this.socketHotPagesAnalysis = socketHotPagesAnalysis;
        this.filePVAnalysis = filePVAnalysis;
        this.setUVAnalysis = setUVAnalysis;
        this.bloomUVAnalysis = bloomUVAnalysis;
        this.channelMarketingAnalysis = channelMarketingAnalysis;
        this.summaryMarketingAnalysis = summaryMarketingAnalysis;
        this.blacklistProvinceAdvertisingAnalysis = blacklistProvinceAdvertisingAnalysis;
        this.timelinessLoginFailAnalysis = timelinessLoginFailAnalysis;
    }

    @GetMapping("/file-hot-items")
    public String fileHotItems() throws Exception {
        fileHotItemsAnalysis.analysis(DEV.getPrefix() + USER_BEHAVIOR_CSV.getFilename());
        return FILE_HOT_ITEMS.getJobName();
    }

    @GetMapping("/kafka-hot-items")
    public String kafkaHotItems() throws Exception {
        kafkaHotItemsAnalysis.analysis();
        return KAFKA_HOT_ITEMS.getJobName();
    }

    @GetMapping("/sql-hot-items")
    public String sqlHotItems() throws Exception {
        sqlHotItemsAnalysis.analysis(DEV.getPrefix() + USER_BEHAVIOR_CSV.getFilename());
        return SQL_HOT_ITEMS.getJobName();
    }

    @GetMapping("/file-hot-pages")
    public String fileHotPages() throws Exception {
        fileHotPagesAnalysis.analysis(DEV.getPrefix() + APACHE_LOG.getFilename());
        return FILE_HOT_PAGES.getJobName();
    }

    @GetMapping("/socket-hot-pages")
    public String socketHotPages() throws Exception {
        socketHotPagesAnalysis.analysis();
        return SOCKET_HOT_PAGES.getJobName();
    }

    @GetMapping("/file-pv")
    public String filePv() throws Exception {
        filePVAnalysis.analysis(DEV.getPrefix() + USER_BEHAVIOR_CSV.getFilename());
        return FILE_PV.getJobName();
    }

    @GetMapping("/set-uv")
    public String setUv() throws Exception {
        setUVAnalysis.analysis(DEV.getPrefix() + USER_BEHAVIOR_CSV.getFilename());
        return SET_UV.getJobName();
    }

    @GetMapping("/bloom-uv")
    public String bloomUv() throws Exception {
        bloomUVAnalysis.analysis(DEV.getPrefix() + USER_BEHAVIOR_CSV.getFilename());
        return BLOOM_UV.getJobName();
    }

    @GetMapping("/channel-marketing")
    public String channelMarketing() throws Exception {
        channelMarketingAnalysis.analysis();
        return CHANNEL_MARKETING.getJobName();
    }

    @GetMapping("/summary-marketing")
    public String summaryMarketing() throws Exception {
        summaryMarketingAnalysis.analysis();
        return SUMMARY_MARKETING.getJobName();
    }

    @GetMapping("/advertising")
    public String advertising() throws Exception {
        blacklistProvinceAdvertisingAnalysis.analysis(DEV.getPrefix() + AD_CLICK_LOG.getFilename());
        return ADVERTISING.getJobName();
    }

    @GetMapping("/login-fail")
    public String loginFail() throws Exception {
        timelinessLoginFailAnalysis.analysis(DEV.getPrefix() + LOGIN_LOG.getFilename());
        return LOGIN_FAIL.getJobName();
    }
}
